﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
dbt = 'user_base';
</cfscript>

<!---重置密码--->
<cffunction name="reset" access="remote" returnFormat="json">
  <cfscript>
	success = 0;
	j = {"success":"0"};
	m_auth = 0;
	</cfscript>
  <cfif isdefined('mobile') and isdefined('userpwd') and isdefined('vcode')>
		<!---判断手机号是否注册--->
    <cfquery datasource="#DB#" name="checkmobile">
    select uid,uuid,muuid
    from user_base
    where mobile = '#mobile#'
    </cfquery>
		<cfif checkmobile.recordcount gt 0>
    	<!---验证码输入--->
      <cfinvoke component="app.cfc.user_userpwdvcode" method="checkvcodecuts" mobile="#mobile#"  vcode="#vcode#" returnvariable="checkvcodecuts" />
      <cfif checkvcodecuts.recordcount eq 0>
				<cfscript>
        //success = 2;
        //验证码不存在或已经过期;
        j = {"success":"0","errCode":"2"};
        </cfscript>
      <cfelseif vcode neq checkvcodecuts.vcode>
				<cfif checkvcodecuts.counts gte 3>
          <cfscript>
          success = 3;
          //j = {"success": success, "msg":"验证码输入错误达到3次"};
          j = {"success":"0","errCode":"2"};
          </cfscript>
          <cfquery datasource="#DB#">
          delete from user_userpwdvcode
          where mobile = '#mobile#'
          </cfquery>
        <cfelse>
          <cfquery datasource="#DB#">
          update user_userpwdvcode set
          counts = counts + 1
          where mobile = '#mobile#'
          </cfquery>
          <cfscript>
          success = 4;
          //j = {"success": success, "msg":"验证码输入错误"};
          j = {"success":"0","errCode":"2"};
          </cfscript>
        </cfif>
        
      <cfelse>
      	<!---更改密码--->
        <cfquery datasource="#DB#">
        UPDATE user_base SET
        userpwd = '#userpwd#'
        where mobile = '#mobile#'
        </cfquery>        
        <cfquery datasource="#DB#">
        delete from user_userpwdvcode
        where mobile = '#mobile#'
        </cfquery>
        
				<cfscript>
        j = {"success": "1", "uuid":checkmobile.muuid};
        </cfscript>
      </cfif>
      
      
      
      
    <cfelse>
			<cfscript>
      //手机没有注册
      j = {"success":"0","errCode":"1"};
      </cfscript>
      
    </cfif>
    	
  <cfelse>
		<cfscript>
    //j = {"success":"0","msg":"缺少参数"};
		j = {"success":"0","errCode":"-1"};
    </cfscript>
  
  </cfif>
     
  
  
  
  
  <cfscript>
	j = createObject("component",'cfjson').encode(j);
  return j;
	</cfscript>

</cffunction>

<!---手机发送短信验证码--->
<cffunction access="remote" name="sendVcode" returnFormat="json">
  <cfscript>
	j = {"success":"0"};
	</cfscript>
  <cfif isdefined('mobile') and isnumeric(mobile)>
  	<cfif len(mobile) eq 11>
			<cfscript>
      //短信平台设置
      actionurl = 'http://121.101.221.34:8888/sms.aspx';
      userid = 1564;
      account = 'jkcs45';
      password = 'jkcs45888';
      vcode = RandRange(100000,999999);
      content = '感谢您在CHINALAOHU.COM注册，验证码为' & vcode & '。客服热线：021-32519063（工作日9-18点）';
      </cfscript>
			<!---判断手机号是否注册--->
      <!---临时取消1--->
      <cfquery datasource="#DB#" name="checkmobile">
      select uid,uuid
      from #dbt#
      where mobile = '#mobile#'
      </cfquery>
      <cfif checkmobile.recordcount eq 0>
      
      	<!---
        <cfhttp url="#actionurl#?action=send&userid=#userid#&account=#account#&password=#password#&mobile=#mobile#&content=#content#" method="GET" result="result" charset="utf-8"></cfhttp>
        --->
        <cfquery datasource="#DB#">
        replace into user_regvcode(mobile,vcode)
        value('#mobile#','#vcode#')
        </cfquery>
        
        <cfscript>
        //xml = xmlparse(result.Filecontent);
        </cfscript>
        <!---<cfdump var="#xml.returnsms#">--->
        
        <cfscript>
        j = {"success":"1"};
        </cfscript>
      <!---临时取消2--->
      <cfelse>
				<cfscript>
        j = {"success":"0","msg":"该手机号已经被注册"};
        </cfscript>
      </cfif>
    <cfelse>
			<cfscript>
			j = {"success":"0"};
      //j = {"success":"0","msg":"目前只支持国内的手机号码"};
      </cfscript>
    </cfif>
  <cfelse>
		<cfscript>
    j = {"success":"0","msg":"请正确填写手机号码"};
    </cfscript>
  </cfif>


	
  <cfscript>
	j = createObject("component",'cfjson').encode(j);
  return j;
	</cfscript>

</cffunction>






<cffunction access="remote" name="vcodeReg" returnFormat="json">
	<cfscript>
  mobile = '13402679077';
  success = 0;
  rs = {"success": success};
  </cfscript>
  <!---判断手机号是否注册--->
  <cfquery datasource="#DB#" name="checkmobile">
  select uid,uuid
  from #dbt#
  where mobile = '#mobile#'
  </cfquery>
  <cfif checkmobile.recordcount eq 0>
  	<!---验证码输入--->
    <cfinvoke component="cfc.plat.user_regvcode" method="checkvcode" mobile="#mobile#" returnvariable="checkvcode" />
    <cfif checkvcode.recordcount eq 0>
    	<!---验证码不存在或已经过期--->
			<cfscript>
			success = 2;
			rs = {"success": success};
      </cfscript>
    <cfelseif vcode neq checkvcode.vcode>
    	<cfif checkvcode.counts gte 3>
				<cfscript>
        success = 3;
        rs = {"success": success};
        </cfscript>
        <cfquery datasource="#DB#">
        delete from user_regvcode
        where mobile = '#mobile#'
        </cfquery>
      <cfelse>
        <cfquery datasource="#DB#">
        update user_regvcode set
        counts = counts + 1
        where mobile = '#mobile#'
        </cfquery>
				<cfscript>
        success = 0;
        rs = {"success": success};
        </cfscript>
      </cfif>
    <cfelse>
      <!---正式注册--->
      <cfquery datasource="#DB#" result="addrs">
      insert into #dbt#(create_dt,mobile)
      values(#now()#,'#mobile#')
      </cfquery>
			<cfscript>
      success = 1;
      rs = {"success": success, "lhid": addrs.GENERATEDKEY};
      </cfscript>
    </cfif>
  <cfelse>
		<cfscript>
    success = 0;
    rs = {"success": success, "lhid":checkmobile.uid};
    </cfscript>
  </cfif>
  <cfreturn rs>
</cffunction>

  
</cfcomponent>